const httpClient = require('./httpClient');

const api_bind_merchant  = 'https://mobiledev.utcook.com/catering/iot/merchant/device/bind'
const api_bind_store = 'https://mobiledev.utcook.com/catering/iot/device/iotChangeBindStore'
const api_login = 'https://oauthdev2.utcook.com/uaa/oauth/token'

// 登录绑定设备
async function loginAndBind(bindInfo) {
    let token = await httpClient.obationAccessToken(api_login, bindInfo.username, bindInfo.password)
    for (const device of bindInfo.devices) {
        let res1 = await httpClient.httpPost(api_bind_merchant, {deviceCgid: device.cgid, token: "Bearer " + token}, token)
        console.log("绑定商家：" + JSON.stringify(res1))
        let res2 = await httpClient.httpPost(api_bind_store, {deviceCgid: device.cgid, storeId: bindInfo.storeId}, token)
        console.log("绑定门店：" + JSON.stringify(res2))
    }
}

module.exports = {
    loginAndBind
}

// 绑定设备
loginAndBind(
    {
        username: "test_ljz",
        password: "Ut123456",
        merchantId: "969494400210046976",
        storeId: "1012153781523279872",
        devices: [
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "daH9JjbfwfN3ITNj644a",
    "ds": "47d8fe8a48c19053eb3b576121766a0b",
    "cgid": "17315494818291462903000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549481345"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "lSJ7s3MPVLoxvzCaipsv",
    "ds": "6241bf8a82b171ff39d81548ed4158f9",
    "cgid": "17315494824981574361000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549482003"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "SxRzJmxnfVxNOo2M0LOz",
    "ds": "c212e327eb407e102f5232b7d8e43e1a",
    "cgid": "17315494832131682841000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549482730"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "GtDISQBie7H4Dg5seJ46",
    "ds": "772e243fef210e9082216db904852e4d",
    "cgid": "17315494838571922188000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549483364"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "ZAtEpnVcL5FvRxrjnvI3",
    "ds": "3ae6d93fb080b9cd9f88ec6b6c147c50",
    "cgid": "17315494845411786867000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549484057"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "YGpcJME15oY3wUr75P2R",
    "ds": "e4fc646b5cd408c0a11f177bd7c9c159",
    "cgid": "17315494852111512477000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549484728"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "IdaZYKWKqBbqnFnlgh7I",
    "ds": "259f658e77541492b028b238c50602b5",
    "cgid": "17315494858131770089000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549485326"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "UxUwk2lhKVLbdYakliLT",
    "ds": "9c73bf84d8fafbabd0b5ab4adbd767e7",
    "cgid": "17315494865061253052000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549486020"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "A7ho00ZapqoMGUr8rfab",
    "ds": "5228e4ae77b15363f393c1e51591ae9a",
    "cgid": "17315494871001288404000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549486670"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "nHhNooOpWo6WW6rsFjzL",
    "ds": "79e1da1c64cf1e26fc6fafff982ad955",
    "cgid": "17315494878561974124000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549487371"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "5BYYCana9JdUSVe4yoYI",
    "ds": "5e29f23b3c76508eb97804197aa31637",
    "cgid": "17315494884621273919000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549487970"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "A6ribOR5Ygb3JF3fOWzL",
    "ds": "d09ed25686a3acbc07cdff7c6abbce6f",
    "cgid": "17315494891981851381000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549488710"
  },
  {
    "pk": "a1Vtf1BLhjM",
    "dn": "6Q6EKipZCM7tkllKCIkL",
    "ds": "3db348a344bc87efa078386156ac2b90",
    "cgid": "17315494898591566721000000000000",
    "pn": "273滚筒标准版2_0版",
    "deviceAlias": "273滚筒标准版2_0版1731549489377"
  }
]
    }
)